set more off

use "\colonialism.dta", clear
mi set, clear
xtset dyadid year

	*Let’s drop these, since they are CURRENT colonial-esque relationships. Hard to know how to treat in our setup
replace colhistory_ruledby=. if threeletterccode=="PSE" & threeletterpcode=="ISR" 
replace av_psng_std=. if threeletterccode=="PSE" & threeletterpcode=="ISR" 


replace colhistory_ruledby=. if country=="Taiwan " & threeletterpcode=="CHN"
replace av_psng_std=. if country=="Taiwan " & threeletterpcode=="CHN"


replace colhistory_ruledby=. if threeletterccode=="HKG" & threeletterpcode=="CHN" 
replace av_psng_std=. if threeletterccode=="HKG" & threeletterpcode=="CHN" 

	*and drop this
drop if threeletterpcode=="EUU"

egen av_psng=std(av_psng_std)

	*recoding a few secession cases having no colonial relationship
replace colhistory_ruledby=0 if threeletterccode=="ECU" & threeletterpcode=="COL"
replace colhistory_ruledby=0 if threeletterccode=="PER" & threeletterpcode=="BOL"
replace colhistory_ruledby=0 if threeletterccode=="URY" & threeletterpcode=="BRA"
replace colhistory_ruledby=0 if threeletterccode=="BGD" & threeletterpcode=="PAK" 

	*These are changes to how COW coded some countries, given what I see to be mistakes in COW. 
replace colhistory_ruledby=1 if threeletterccode=="PSE" & threeletterpcode=="TUR" /*Updating to past colonizer*/
replace colhistory_ruledby=1 if threeletterccode=="HKG" & threeletterpcode=="GBR" /*Seems wrong on COW's part*/
replace colhistory_ruledby=1 if threeletterccode=="EGY" & threeletterpcode=="GBR" /*Seems wrong on COW's part*/
replace colhistory_ruledby=1 if threeletterccode=="TUN" & threeletterpcode=="FRA" /*Seems wrong on COW's part*/
replace colhistory_ruledby=0 if threeletterccode=="BTN" & threeletterpcode=="IND" /*Never really colonized by India*/
replace colhistory_ruledby=0 if threeletterccode=="BTN" & threeletterpcode=="GBR" /*Never really colonized by Great Britain*/

	*These are changes to date of sovereignty from the metropole in question. 
gen colhistory_inddate_orig=colhistory_inddate
replace colhistory_inddate=1776 if threeletterccode=="USA" 
replace colhistory_inddate=1947 if threeletterccode=="BGD" 
replace colhistory_inddate=1634 if threeletterccode=="BTN" 
replace colhistory_inddate=1810 if threeletterccode=="COL" 
replace colhistory_inddate=1821 if threeletterccode=="CRI" 
replace colhistory_inddate=1821 if threeletterccode=="DOM" 
replace colhistory_inddate=1822 if threeletterccode=="ECU" 
replace colhistory_inddate=1867 if threeletterccode=="EGY" 
replace colhistory_inddate=1922 if threeletterccode=="EGY" & threeletterpcode=="GBR" 
replace colhistory_inddate=1822 if threeletterccode=="GRC" 
replace colhistory_inddate=1821 if threeletterccode=="GTM" 
replace colhistory_inddate=1997 if threeletterccode=="HKG" 
replace colhistory_inddate=1821 if threeletterccode=="HND" 
replace colhistory_inddate=1918 if threeletterccode=="ISR" 
replace colhistory_inddate=1948 if threeletterccode=="ISR" & threeletterpcode=="GBR"
replace colhistory_inddate=1918 if threeletterccode=="JOR"
replace colhistory_inddate=1917 if threeletterccode=="LBN"
replace colhistory_inddate=1943 if threeletterccode=="LBN" & threeletterpcode=="FRA"
replace colhistory_inddate=1991 if threeletterccode=="LTU" 
replace colhistory_inddate=1956 if threeletterccode=="MAR" 
replace colhistory_inddate=1821 if threeletterccode=="NIC" 
replace colhistory_inddate=1819 if threeletterccode=="PAN" 
replace colhistory_inddate=1915 if threeletterccode=="POL" 
replace colhistory_inddate=1918 if threeletterccode=="POL" & threeletterpcode=="RUS"
replace colhistory_inddate=1917 if threeletterccode=="PSE" 
	replace colhistory_inddate=1821 if threeletterccode=="SLV" 
replace colhistory_inddate=1956 if threeletterccode=="TUN" & threeletterpcode=="FRA"
replace colhistory_inddate=1811 if threeletterccode=="URY" 
replace colhistory_inddate=1811 if threeletterccode=="VEN" 

	*These are changes to violence at independence
replace colhistory_indviol=0 if threeletterccode=="BGD" /* COW codes this as secession from Pakistan, but we are treating as indep from GBR, which ICOW codes as 0 */
replace colhistory_indviol=1 if threeletterccode=="TUN" & threeletterpcode=="FRA" /*this is in the War list at http://www.systemicpeace.org/warlist/warlist.htm */
replace colhistory_indviol=1 if threeletterccode=="ISR" & threeletterpcode=="TUR" /*yes because of Great Arab Revolt against Ottomans*/
replace colhistory_indviol=1 if threeletterccode=="PSE" & threeletterpcode=="TUR" /*yes because of Great Arab Revolt against Ottomans*/
replace colhistory_indviol=1 if threeletterccode=="LBN" & threeletterpcode=="TUR" /*yes because of Great Arab Revolt against Ottomans*/
replace colhistory_indviol=0 if threeletterccode=="HKG" & threeletterpcode=="GBR" /*peaceful transfer to China*/
replace colhistory_indviol=1 if threeletterccode=="EGY" & threeletterpcode=="GBR" /*Egyptian Revolution of 1919*/
replace colhistory_indviol=0 if threeletterccode=="LTU" & threeletterpcode=="RUS" /*Violence by Soviets but Lithuanians largely peaceful, so 0 to be consistent with ICOW*/
replace colhistory_indviol=1 if threeletterccode=="MAR" & threeletterpcode=="FRA" /*Moroccan Liberation Army activities */
replace colhistory_indviol=1 if threeletterccode=="POL" & threeletterpcode=="RUS" /*Central Powers violence against Russian troops*/

	*These are changes to Easterly's EuroShare variable
replace coleuroshare_easterly=.094 if threeletterccode=="LTU"  /*Soviet Politics in Perspective(1998) p. 244*/
replace coleuroshare_easterly=.221 if threeletterccode=="UKR"  /*Soviet Politics in Perspective(1998) p. 244*/
replace coleuroshare_easterly=.056 if threeletterccode=="AZE"  /*Soviet Politics in Perspective(1998) p. 244*/
replace coleuroshare_easterly=.095 if threeletterccode=="TKM"  /*Soviet Politics in Perspective(1998) p. 244*/
replace coleuroshare_easterly=.076 if threeletterccode=="TJK"  /*Soviet Politics in Perspective(1998) p. 244*/
replace coleuroshare_easterly=.215 if threeletterccode=="KGZ"  /*Soviet Politics in Perspective(1998) p. 244*/
replace coleuroshare_easterly=.083 if threeletterccode=="UZB"  /*Soviet Politics in Perspective(1998) p. 244*/
replace coleuroshare_easterly=.378 if threeletterccode=="KAZ"  /*Soviet Politics in Perspective(1998) p. 244*/
replace coleuroshare_easterly=8000/2700000 if threeletterccode=="FIN" /*https://en.wikipedia.org/wiki/Russification_of_Finland CAN'T FIND SOURCE FOR THIS BUT THE NUMBER CLEARLY IS SMALL*/
replace coleuroshare_easterly=.0248 if threeletterccode=="KOR" /*Japanese population in Korea in 1930. Standards of Living in Colonial Korea: Did the Masses Become Worse Off or Better Off Under Japanese Rule?   Mitsuhiko Kimura The Journal of Economic History , Sep., 1993, Vol. 53, No. 3 (Sep., 1993), pp.629-652*/
replace coleuroshare_easterly=0 if threeletterccode=="MDV" /*No evidence of British settlement, similar to other South Asian countries*/
replace coleuroshare_easterly=(597100+264800+430500+48400+80000)/(597100*(1/.39)+264800*(1/.49)+430500*(1/.36)+(48400+80000)*(1/.5)) if threeletterccode=="GRC" /*Based on Edirne, Selanik, Yanya, Crete, and Islands from Table 3.7, p. 56 of _Ottoman Population 1830-1914_ by Kemal Karpat (1985) */ 
replace coleuroshare_easterly=.6 if threeletterccode=="URY" /* email from Cupery on 4/14/21 discusses this decision. Cites: https://www.britannica.com/place/Uruguay/Sports-and-recreation#ref407712  and https://www.oxfordbibliographies.com/view/document/obo-9780199766581/obo-9780199766581-0192.xml and https://www.blackpast.org/global-african-history/perspectives-global-african-history/afro-uruguay-brief-history/ and McDermott, Alicia. "The Last of the Charrua: The Honored Warrior Tribe of Uruguay". www.ancient-origins.net. (https://en.wikipedia.org/wiki/Indigenous_peoples_in_Uruguay) */
replace coleuroshare_easterly=10000/700000 if threeletterccode=="MNG"  /* This figure comes from https://en.wikipedia.org/wiki/Ethnic_Chinese_in_Mongolia  Unfortunately, the figure is not cited, but clearly the number if very low */
replace coleuroshare_easterly=0 if threeletterccode=="POL"  /* For RUS. email from Cupery on 4/13/21 details this decision */
replace coleuroshare_easterly=.30 if threeletterccode=="POL" & threeletterpcode=="DEU" /* this page has numbers and cites: https://en.wikipedia.org/wiki/Germanisation_of_Poles_during_the_Partitions */
replace coleuroshare_easterly=0 if threeletterccode=="ISR" /* for GBR. althouugh lots of Jewish emigration to Israel during the mandate, it seems very little of it from UK: https://reformjudaism.org/history-jewish-immigration-israel-aliyah and https://www.jpr.org.uk/documents/Immigration%20from%20the%20United%20Kingdom%20to%20Israel.pdf */
replace coleuroshare_easterly=. if threeletterccode=="ISR" & threeletterpcode=="TUR" /*simply not available in _Ottoman Population 1830-1914_ by Kemal Karpat (1985)*/
replace coleuroshare_easterly=0 if threeletterccode=="PSE"  /* For GBR. althouugh lots of Jewish emigration to Israel during the mandate, it seems very little of it from UK: https://reformjudaism.org/history-jewish-immigration-israel-aliyah and https://www.jpr.org.uk/documents/Immigration%20from%20the%20United%20Kingdom%20to%20Israel.pdf */
replace coleuroshare_easterly=. if threeletterccode=="PSE" & threeletterpcode=="TUR" /*simply not available in _Ottoman Population 1830-1914_ by Kemal Karpat (1985)*/
replace coleuroshare_easterly=0 if threeletterccode=="TUN" & threeletterpcode=="TUR" /*Table 1.2A and 1.2B on page 116 of _Ottoman Population 1830-1914_ by Kemal Karpat (1985)*/
replace coleuroshare_easterly=0 if threeletterccode=="EGY" & threeletterpcode=="TUR" /*Table 1.2A and 1.2B on page 116 of _Ottoman Population 1830-1914_ by Kemal Karpat (1985)*/ /*Two other sources suggest it's 2 to 3 percent: "Turks", Egypt: Lower Egypt, with the Fayûm and the peninsula of Sinai, Part 1 of Egypt: Handbook for Travellers, K. Baedeker, 1878, p. 52 and https://www.cairoscene.com/Buzz/National-Geographic-s-DNA-Analysis-Proves-Egyptians-Are-Only-17-Arab */
replace coleuroshare_easterly=.98 if country=="Taiwan " /*Taiwan is 98% from mainland. filling this in just so not missing when controlling for euroshare */
replace coleuroshare_easterly=. if threeletterccode=="JOR" & threeletterpcode=="TUR" /*simply not available in _Ottoman Population 1830-1914_ by Kemal Karpat (1985)*/
replace coleuroshare_easterly=. if threeletterccode=="LBN" & threeletterpcode=="TUR" /* simply not available in _Ottoman Population 1830-1914_ by Kemal Karpat (1985). Contemporary figures here: https://web.archive.org/web/20180620232105/https://english.al-akhbar.com/content/lebanese-turks-seek-political-and-social-recognition and https://web.archive.org/web/20160303181832/http://www.orsam.org.tr/en/enUploads/Article/Files/2010110_sayi11_eng_web.pdf  It really depends on the timing under colonialism, but this contemporary figure represents fact that it was never large*/  
replace coleuroshare_easterly=0 if threeletterccode=="COD" /* not sure why this is missing from Easterly */

*Figure bar chart of target countries
gen tempcolonizer=partner if colhistory_ruledby==1 & av_psng~=.
gen tempcolonizer1=strltrim(tempcolonizer)
gen colonizer=strrtrim(tempcolonizer1)
replace colonizer="UK" if colonizer=="United Kingdom"
replace colonizer="USA" if colonizer=="United States"

label values colhistory_ruledby pcode
label values colhistory_secfrom pcode

gen countryfig=country
label variable countryfig "{bf:Former Colonizer (Target Country)}"

	egen count=count(colonizer), by(colonizer)
*Get N for each dyad
tab country if colhistory_ruledby==1 & threeletterpcode=="ESP" & av_psng~=.
tab country if colhistory_ruledby==1 & threeletterpcode=="GBR" & av_psng~=.
tab country if colhistory_ruledby==1 & threeletterpcode=="TUR" & av_psng~=.
tab country if colhistory_ruledby==1 & threeletterpcode=="RUS" & av_psng~=.
tab country if colhistory_ruledby==1 & threeletterpcode=="USA" & av_psng~=.
tab country if colhistory_ruledby==1 & threeletterpcode=="JPN" & av_psng~=.
tab country if colhistory_ruledby==1 & threeletterpcode=="FRA" & av_psng~=.
tab country if colhistory_ruledby==1 & threeletterpcode=="DEU" & av_psng~=.
tab country if colhistory_ruledby==1 & threeletterpcode=="CHN" & av_psng~=.

catplot countryfig if av_psng~=., var1opts(sort(1) descending label(angle(vertical))) ///
over(colonizer, sort(count) descending) stack asyvars ytitle({bf:Number of Observations}) graphregion(color(white)) plotregion(lstyle(yxline) lcolor(black)) bar(1, color(black)) b1title("") legend(off) ///
text(6.5 95.25 "CO", size(vsmall) color(white) placement(c)) text(19.5 95.25 "EC", size(vsmall) color(white) placement(c)) text(32.5 95.25 "MX", size(vsmall) color(white) placement(c)) ///
text(45 95.25 "AR", size(vsmall) color(white) placement(c)) text(57 95.25 "PE", size(vsmall) color(white) placement(c)) text(69 95.25 "BO", size(vsmall) color(white) placement(c)) ///
text(80.25 95.25 "CL", size(vsmall) color(white) placement(c)) text(90.5 95.25 "CR", size(vsmall) color(white) placement(c)) text(101.5 95.25 "SV", size(vsmall) color(white) placement(c)) ///
text(112.5 95.25 "GT", size(vsmall) color(white) placement(c)) text(123.5 95.25 "HN", size(vsmall) color(white) placement(c)) text(134.5 95.25 "NI", size(vsmall) color(white) placement(c)) ///
text(145.5 95.25 "PA", size(vsmall) color(white) placement(c)) text(156.75 95.25 "PY", size(vsmall) color(white) placement(c)) text(167.5 95.25 "UY", size(vsmall) color(white) placement(c)) ///
text(178.75 95.25 "VE", size(vsmall) color(white) placement(c)) text(189 95.25 "DO", size(vsmall) color(white) placement(c)) ///
text(6 84 "IN", size(vsmall) color(white) placement(c)) text(18 84 "US", size(vsmall) color(white) placement(c)) text(29.5 84 "CA", size(vsmall) color(white) placement(c)) ///
text(40 84 "NG", size(vsmall) color(white) placement(c)) text(49.5 84 "AU", size(vsmall) color(white) placement(c)) text(58.5 84 "KE", size(vsmall) color(white) placement(c)) ///
text(66.5 84 "PK", size(vsmall) color(white) placement(c)) text(73 84 "EG", size(vsmall) color(white) placement(c)) text(79 84 "GH", size(vsmall) color(white) placement(c)) ///
text(83.5 84 "ZA", size(tiny) color(white) placement(c) orient(vertical)) text(86.5 84 "LK", size(tiny) color(white) placement(c) orient(vertical)) ///
text(89 84 "AF", size(tiny) color(white) placement(c) orient(vertical)) text(91.25 84 "MY", size(tiny) color(white) placement(c) orient(vertical)) ///
text(93 84 "SG", size(tiny) color(white) placement(c) orient(vertical)) text(95 84 "AE", size(tiny) color(white) placement(c) orient(vertical)) ///
text(96.5 88.25 "BD", size(tiny) color(black) placement(c)) text(97.7 79.5 "HK", size(tiny) color(black) placement(c)) /// 
text(98.75 89.75 "IQ", size(tiny) color(black) placement(c)) text(100 78 "IL", size(tiny) color(black) placement(c))  /// 
text(100.5 88.25 "MV", size(tiny) color(black) placement(c)) text(101.75 79.5 "TZ", size(tiny) color(black) placement(c)) /// 
text(103 89.75 "ZW", size(tiny) color(black) placement(c)) ///
text(3 61.5 "JO", size(vsmall) color(white) placement(c)) text(9 61.5 "LB", size(vsmall) color(white) placement(c)) text(14 61.5 "EG", size(vsmall) color(white) placement(c) orient(vertical)) ///
text(18 61.5 "IL", size(vsmall) color(white) placement(c) orient(vertical)) text(21.5 61.5 "PS", size(tiny) color(white) placement(c) orient(vertical)) ///
text(24.5 61.5 "TN", size(tiny) color(white) placement(c) orient(vertical)) text(26.75 57 "GR", size(tiny) color(black) placement(c)) ///
text(6.5 72.75 "PL", size(vsmall) color(white) placement(c)) text(14.75 72.75 "UA", size(vsmall) color(white) placement(c)) ///
text(19.5 72.75 "UZ", size(tiny) color(white) placement(c) orient(vertical)) ///
text(24.25 77 "AZ", size(tiny) color(black) placement(c)) text(23 68.25 "FI", size(tiny) color(black) placement(c)) /// 
text(26.5 78.75 "KZ", size(tiny) color(black) placement(c)) text(27.5 68.25 "KG", size(tiny) color(black) placement(c)) /// 
text(22 72.75 "LT", size(tiny) color(black) orient(vertical) placement(c)) text(28.75 77 "TJ", size(tiny) color(black) placement(c)) text(25.5 66.5 "TM", size(tiny) color(black) placement(c)) ///
text(7.5 50.25 "PH", size(vsmall) color(white) placement(c)) text(6 38.75 "KR", size(vsmall) color(white) placement(c)) ///
text(2 16.25 "LB", size(vsmall) color(white) placement(c) orient(vertical)) text(5 16.25 "SN", size(tiny) color(black) placement(c) orient(vertical)) ///
text(6.5 20.5 "MA", size(tiny) color(black) placement(c)) text(7.75 11.5 "TN", size(tiny) color(black) placement(c)) ///
text(4.25 27.5 "PL", size(vsmall) color(white) placement(c)) text(4.25 4.75 "MN", size(vsmall) color(black) placement(c)) ///
text(200 95.25 "17", size(small) color(black) placement(c)) ///
text(200 84 "22", size(small) color(black) placement(c)) ///
text(200 61.5 "7", size(small) color(black) placement(c)) ///
text(200 72.75 "10", size(small) color(black) placement(c)) ///
text(200 50.25 "1", size(small) color(black) placement(c)) ///
text(200 38.75 "1", size(small) color(black) placement(c)) ///
text(200 16.25 "4", size(small) color(black) placement(c)) ///
text(200 27.5 "1", size(small) color(black) placement(c)) ///
text(200 4.75 "1", size(small) color(black) placement(c)) ///
text(200 101 "# of dyads", size(small) color(black) placement(c)) ///
yscale(range(0 207))

gen relative_gdpcapita=gdpcapita_p/gdpcapita
gen relative_gdpcapita2=gdpcapita_p - gdpcapita
gen lnrel_gdpcapita2=ln(relative_gdpcapita)
gen lngdpcapita_p=ln(gdpcapita_p)
gen lngdpcapita=ln(gdpcapita)

	**change labels to make them shorter for use in Word
label variable av_psng "Opinionijt" 
label variable lntrd_imf_gdp "Tradeijt"
label variable lnimp_imf_gdp "Importsijt"
label variable lnexp_imf_gdp "Exportsijt"
label variable crdyad "BBC Globescan dyad"
label variable lbdyad "Latinbarometer dyad"
label variable mamdyad "Mexico, Americas and the World dyad"
label variable pwdyad "Pew Global Attitudes dyad"
label variable asbdyad "Asian Barometer dyad"
label variable asb1dyad "Asia Barometer dyad"
label variable alliance_activealliance "Int'l alliance active as of 12/31/2012"
label variable colhistory_ruledby "Former colonyij"
label variable Wlang_commonlang "Common official language"
label variable lnfdistock_gdp "FDI stockij,t"
label variable lnaid_gdp "Development assistanceij,t"
label variable lngdpcapita_p "GDP per capitajt"
label variable lngdpcapita "GDP per capitait"


*ANALYSES
eststo clear
ttest av_psng, by(colhistory_ruledby)

*TABLE 1
	**Simple model with colonial dyad only
eststo: xtreg av_psng colhistory_ruledby lbdyad mamdyad crdyad asb1dyad pwdyad, be 
	** here's how I convert sd's into points
reg crproppos av_psng
reg pw_propart2 av_psng

	*Model 1.1: Home country fixed effects
eststo: xtreg av_psng colhistory_ruledby lbdyad mamdyad crdyad asb1dyad pwdyad i.ccode i.year, be
gen esample=e(sample)

	*Dyadic answers
	*Model 1.5: time since indep
			gen years_since_indep=year-colhistory_inddate
			sum years_since if av_psng~=. & colhistory_ruledby==1, det
	
			replace years_since =(years_since-r(p50))/100
eststo: xtreg av_psng i.colhistory_ruledby##c.years_since_indep lbdyad mamdyad crdyad asb1dyad pwdyad i.year, be 

	*Model 1.2: Indigenous mortality
eststo: xtreg av_psng i.colhistory_ruledby##c.indigmort_easterly lbdyad mamdyad crdyad asb1dyad pwdyad i.year, be 

	*Model 1.3: violence at indep
eststo: xtreg av_psng i.colhistory_ruledby##i.colhistory_indviol lbdyad mamdyad crdyad asb1dyad pwdyad i.year, be 

	*Model 1.4: Euro Share
*	replace coleuroshare_easterly=coleuroshare_easterly-.07 
eststo: xtreg av_psng i.colhistory_ruledby##c.coleuroshare_easterly lbdyad mamdyad crdyad asb1dyad pwdyad i.year , be 
gen esample2=e(sample)

eststo: xtreg av_psng i.colhistory_ruledby##i.settler_paine mamdyad crdyad asb1dyad pwdyad , be 
		*
eststo: xtreg av_psng c.colhistory_ruledby##ib712.ccode lbdyad mamdyad crdyad asb1dyad pwdyad i.ccode , be

eststo clear


*TABLE A5
	*Model A5.1: language
eststo: xtreg av_psng colhistory_ruledby Wlang_commonlang lbdyad mamdyad crdyad asb1dyad pwdyad i.ccode i.year, be 

	*Model A5.2: fdistock
eststo: xtreg av_psng colhistory_ruledby fdistock_gdp  lbdyad mamdyad crdyad asb1dyad pwdyad i.ccode  i.year, be 

	*Model A5.3: aid_GDP 
eststo: xtreg av_psng colhistory_ruledby aid_gdp lbdyad mamdyad crdyad asb1dyad pwdyad i.ccode  i.year, be 

eststo clear

*TABLE 2
	**Model 2.1 Monadic answer: target fixed effects 
eststo: xtreg av_psng colhistory_ruledby lbdyad mamdyad crdyad asb1dyad pwdyad i.ccode i.year i.b625.pcode , be 
mat define b=e(b)
mat define B=b'
svmat B

gen lngdpcurrentus_p=ln(gdpcurrentus_p)

	**Monadic substantive answer
		*Model 2.2
eststo: xtreg av_psng colhistory_ruledby polity2_p lngdpcurrentus_p  lngdpcapita_p lbdyad mamdyad crdyad asb1dyad pwdyad i.ccode i.year , be 

		*Model 2.3
eststo: xtreg av_psng colhistory_ruledby polity2_p lbdyad mamdyad crdyad asb1dyad pwdyad i.ccode i.year , be 

		*Model 2.4
eststo: xtreg av_psng colhistory_ruledby lngdpcurrentus_p  lbdyad mamdyad crdyad asb1dyad pwdyad i.ccode i.year , be 

		*Model 2.5
eststo: xtreg av_psng colhistory_ruledby lngdpcapita_p lbdyad mamdyad crdyad asb1dyad pwdyad i.ccode i.year , be 

		*Model 2.6
		*Frankel and Romer thing
recode sharedborder (2=1) (1=0)
gen lnpopulation=ln(population)
gen lnpopulation_p=ln(population_p)

eststo: xtivreg av_psng colhistory_ruledby polity2_p lngdpcurrentus_p lngdpcapita_p lbdyad mamdyad crdyad asb1dyad pwdyad i.ccode i.year (lntrd_imf_gdp = sharedborder distance landlocked_dyad lnarea lnarea_p lnpopulation lnpopulation_p i.sharedborder#c.distance i.sharedborder#c.landlocked_dyad i.sharedborder#c.lnarea i.sharedborder#c.lnarea_p i.sharedborder#c.lnpopulation i.sharedborder#c.lnpopulation_p), be first

		*Model 2.7
eststo: xtreg av_psng colhistory_ruledby polity2_p lngdpcurrentus_p  lngdpcapita_p Wlang_commonlang wrelig_sharedrel_gennrel lbdyad mamdyad crdyad asb1dyad pwdyad i.ccode i.year , be 

		*Model 2.8
eststo: xtivreg av_psng colhistory_ruledby polity2_p lngdpcurrentus_p lngdpcapita_p Wlang_commonlang wrelig_sharedrel_gennrel lbdyad mamdyad crdyad asb1dyad pwdyad i.ccode i.year (lntrd_imf_gdp = sharedborder distance landlocked_dyad lnarea lnarea_p lnpopulation lnpopulation_p i.sharedborder#c.distance i.sharedborder#c.landlocked_dyad i.sharedborder#c.lnarea i.sharedborder#c.lnarea_p i.sharedborder#c.lnpopulation i.sharedborder#c.lnpopulation_p), be first

*Balance
xtreg polity2_p colhistory_ruledby i.ccode i.year if av_psng~=., be 
xtreg lngdpcurrentus_p colhistory_ruledby i.ccode i.year if av_psng~=., be 
xtreg lngdpcapita_p colhistory_ruledby i.ccode i.year if av_psng~=., be 
xtreg lntrd_imf_gdp colhistory_ruledby i.ccode i.year if av_psng~=., be 
xtreg wrelig_sharedrel_gennrel colhistory_ruledby i.ccode i.year if av_psng~=., be 

	*Afrobarometer
ttest afb_parthelp2, by(colhistory_ruledby)
xtreg afb_parthelp2 colhistory_ruledby , be

	*Zimbabwe case study
preserve
keep if threeletterccode=="ZWE"
drop if av_psng==.
pwcorr av_psng polity2_p lngdpcurrentus_p lntrd_imf_gdp lnfdistock_gdp lnaid_gdp, obs
restore

	*Mexico case study
	*Table A6
	*Model A.1
xtreg av_psng polity2_p lngdpcurrentus_p lngdpcapita_p lbdyad mamdyad crdyad asb1dyad pwdyad  if threeletterccode=="MEX", be
	*Model A.2
xtivreg av_psng polity2_p lngdpcurrentus_p lngdpcapita_p Wlang_common lbdyad mamdyad crdyad asb1dyad pwdyad (lntrd_imf_gdp = sharedborder distance landlocked_dyad lnarea lnarea_p lnpopulation lnpopulation_p i.sharedborder#c.distance i.sharedborder#c.landlocked_dyad i.sharedborder#c.lnarea i.sharedborder#c.lnarea_p i.sharedborder#c.lnpopulation i.sharedborder#c.lnpopulation_p) if threeletterccode=="MEX", be first

preserve
keep if threeletterccode=="MEX"

collapse (mean) av_psng polity2_p lngdpcurrentus_p  lngdpcapita_p lntrd_imf_gdp (lastnm) threeletterccode country threeletterpcode partner if threeletterccode=="MEX", by (pcode)

corr av_psng polity2_p lngdpcurrentus_p  lngdpcapita_p lntrd_imf_gdp 

reg av_psng polity2_p 
predict xb1 
twoway (scatter av_psng xb1 polity2_p if threeletterpcode~="ESP", mlabel(threeletterpcode) mlabpos(0) msym(o i) mlabcolor(black) mcolor(white) connect(. l) lcolor(gs8 gs8))   ///
(scatter av_psng polity2_p if threeletterpcode=="ESP", mlabel(threeletterpcode) mlabpos(0) msym(o) mlabcolor(black) mlabsize(medlarge) mcolor(white)), ///
xtitle("{bf:Degree of Democracy}" "{it:(Polity{sub:j}})") ytitle("{bf: Average Incoming Favorability from Mexico}") legend(off) yline(0, lcolor(black) lwidth(vthin)) ///
note("{it:r} = +.61") graphregion(color(white)) plotregion(lstyle(yxline) lcolor(black)) xscale(range(-10.5 10.5)) ylab(-1.5 "-1.5SD" -1 "-1SD" -.5 "-.5SD" 0 "0SD" .5 ".5SD" 1 "1SD")

reg av_psng lngdpcurrentus_p  
predict xb2 
twoway (scatter av_psng xb2 lngdpcurrentus_p if threeletterpcode~="ESP", mlabel(threeletterpcode) mlabpos(0) msym(o i) mlabcolor(black) mcolor(white) connect(. l) lcolor(gs8 gs8))  ///
(scatter av_psng lngdpcurrentus_p if threeletterpcode=="ESP", mlabel(threeletterpcode) mlabpos(0) msym(o) mlabcolor(black) mlabsize(medlarge) mcolor(white)), ///
xtitle("{bf:Size of Economy}" "{it:(GDP{sub:j}})") ytitle("{bf: Average Incoming Favorability from Mexico}") legend(off) yline(0, lcolor(black) lwidth(vthin)) ///
note("{it:r} = +.42") graphregion(color(white)) plotregion(lstyle(yxline) lcolor(black))  xscale(range(23.25 30.25)) xlab(23.025851 "$10 billion"  25.328436 "$100 billion" 27.631021 "$1 trillion" 29.933606 "$10 trillion") ylab(-1.5 "-1.5SD" -1 "-1SD" -.5 "-.5SD" 0 "0SD" .5 ".5SD" 1 "1SD")


reg av_psng lntrd_imf_gdp   
predict xb3 
twoway (scatter av_psng xb3 lntrd_imf_gdp if threeletterpcode~="ESP", mlabel(threeletterpcode) mlabpos(0) msym(o i) mlabcolor(black) mcolor(white) connect(. l) lcolor(gs8 gs8) )   ///
(scatter av_psng lntrd_imf_gdp if threeletterpcode=="ESP", mlabel(threeletterpcode) mlabpos(0) msym(o) mlabcolor(black) mlabsize(medlarge) mcolor(white)), ///
xtitle("{bf:Trade with Mexico (as a proportion of Mexico's GDP)}" "{it:(Trade{sub:ij}})") ytitle("{bf: Average Incoming Favorability from Mexico}") legend(off) yline(0, lcolor(black) lwidth(vthin)) ///
note("{it:r} = +.58") graphregion(color(white)) plotregion(lstyle(yxline) lcolor(black)) xscale(range(-12.5 -.75)) ylab(-1.5 "-1.5SD" -1 "-1SD" -.5 "-.5SD" 0 "0SD" .5 ".5SD" 1 "1SD") xlab(-10.414313 ".00003" -8.1117281 ".0003" -5.809143 ".003" -3.5065579 ".03" -1.2039728 ".3")
restore 
*-----------------

collapse (mean) av_psng (lastnm) threeletterccode country threeletterpcode partner, by (ccode colhistory_ruledby pcode)
drop if av_psng==.
tab ccode colhistory_ruledby
sort ccode colhistory_ruledby

gen lag=colhistory_ruledby[_n-1]
gen one=1 if lag==1 & colhistory_ruledby==1
gen account=0
replace account=1 if colhistory_ruledby==1 & one~=1
replace account=2 if colhistory_ruledby==1 & one==1

collapse (mean) av_psng (lastnm) threeletterccode country threeletterpcode partner, by (ccode account)
gen av_psnglag=av_psng[_n-1]
gen av_psnglag2=av_psng[_n-2]

gen col_diff=av_psng-av_psnglag if account==1
replace col_diff=av_psng-av_psnglag2 if account==2

keep if col_diff~=.
sort col_diff
gen n=_n

capture label drop cc
label define cc 1 MNG 2 POL 3 GRC 4 IRQ 5 FIN 6 PAK 7 ISR 8 LTU 9 MYS 10 KOR 11 UKR 12 BGD 13 TKM 14 LKA 15 MDV 16 ARE 17 AFG 18 LBN 19 "{bf:ZWE}" 20 EGY 21 TZA 22 ECU 23 VEN 24 EGY 25 "{bf:MEX}" 26 AZE 27 IND 28 CHL 29 POL 30 BOL 31 NIC 32 NGA 33 TJK 34 GTM 35 ARG 36 PER 37 PRY 38 COL 39 LBN 40 KEN 41 SGP 42 GHA 43 SLV 44 JOR 45 URY 46 HND 47 CRI 48 PAN 49 AUS 50 SEN 51 PSE 52 CAN 53 TUN 54 PHL 55 MAR 56 ZAF 57 KGZ 58 UZB 59 DOM 60 USA 61 ISR 62 HKG 63 KAZ 64 TUN   
*label define cc 1 MNG 2 "POL" 3 GRC 4 IRQ 5 FIN 6 PAK 7 "{bf:ISR}" 8 LTU 9 MYS 10 KOR 11 UKR 12 BGD 13 TKM 14 LKA 15 MDV 16 ARE 17 AFG 18 "{bf:LBN}" 19 "{bf:ZWE}" 20 "{bf:EGY}" 21 TZA 22 ECU 23 VEN 24 "{bf:EGY}" 25 "{bf:MEX}" 26 AZE 27 IND 28 CHL 29 "{bf:POL}" 30 BOL 31 NIC 32 NGA 33 TJK 34 GTM 35 ARG 36 PER 37 PRY 38 COL 39 "{bf:LBN}" 40 KEN 41 SGP 42 GHA 43 SLV 44 JOR 45 URY 46 HND 47 CRI 48 PAN 49 AUS 50 SEN 51 PSE 52 CAN 53 "{bf:TUN}" 54 PHL 55 MAR 56 ZAF 57 KGZ 58 UZB 59 DOM 60 USA 61 "{bf:ISR}" 62 HKG 63 KAZ 64 "{bf:TUN}"   
label values n cc 

gen Spain=col_diff if threeletterpcode=="ESP"
gen UK=col_diff if threeletterpcode=="GBR"
gen Turkey=col_diff if threeletterpcode=="TUR"
gen Russia =col_diff if threeletterpcode=="RUS"
gen Other=col_diff if threeletterpcode=="CHN" | threeletterpcode=="JPN" | threeletterpcode=="FRA" | threeletterpcode=="USA" | threeletterpcode=="DEU" 

scatter col_diff n, msize(medsmall) mcolor(black) graphregion(color(white)) plotregion(lstyle(yxline) lcolor(black)) xtitle("{bf:Home Country (Former Colony)}") ytitle("{bf:Opinion of Former Colonizer - Opinion of All Other}" "{bf:Targets}") ///
xlab(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64, valuelabel labsize(vsmall) angle(vertical)) 

*Figure 1
twoway (scatter Spain n, msym(circle) msize(medsmall) mcolor(black)) ///
(scatter UK n, msym(diamond) msize(medsmall) mcolor(black)) ///
(scatter Turkey n, msym(triangle) msize(medsmall) mcolor(black)) ///
(scatter Russia n, msym(square) msize(medsmall) mcolor(black)) ///
(scatter Other n, msym(plus) msize(medsmall) mcolor(black)), ///
graphregion(color(white)) plotregion(lstyle(yxline) lcolor(black)) xtitle("{bf:Home Country (Former Colony)}") ytitle("{bf:Average Opinion of Former Colonizer - Average}" "{bf:Opinion of All Other Targets}")  ///
legend(title("Former Colonizer", size(vsmall)) rows(1) ring(0) bplacement(n) size(vsmall) keygap(0.5)) ///
ylab(-2 "-2SD" -1 "-1SD" 0 "0SD" 1 "1SD" 2 "2SD", nogrid) yline(0, lcolor(black) lwidth(vthin)) /// 
xlab(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64, grid valuelabel labsize(vsmall) angle(vertical)) 

gen col_col_diff=av_col_-av_psnglag if account==1


